<?php
/*
Plugin Name: Tat Theme Setting
Plugin URI: http://www.tat.vn/wordpress-plugins/tat-show-hot-news
Description: Setting Tat Theme
Version: 1.0
Author: Truong Le and Tuan Su
Author URI: http://www.tat.vn
License: GPLv2
*/

define ( 'TAT_WPMUT_PLUGIN_URL', plugin_dir_url(__FILE__)); // with forward slash (/).

register_activation_hook ( __FILE__, 'tat_themes_settings_install' );

function tat_themes_settings_install() {
	global $wp_version;

	if( version_compare( $wp_version, '3.4', '<' ) ) {
		wp_die( 'This plugin requires Wordpress version 3.4 or higher.' );
	}
	
	$tat_theme_options_arr = array (
		'num_of_show_tat_hot_news' => 5
	);
	
	update_option( 'tat_theme_options_arr' , $tat_theme_options_arr );
}


add_action( 'admin_menu', 'tat_themes_settings_submenu' );

function tat_themes_settings_submenu() {
	add_options_page( 'Show Tat Theme Setting Page','Tat Theme Setting', 'manage_options','tat_theme_settings_menu', 'tat_theme_setting_page' );
	
	add_action( 'admin_init', 'tat_themes_register_settings' );
}

function tat_themes_register_settings() {
	register_setting( 'tat-theme-settings', 'tat_theme_options_arr', '');
}

function tat_wpmut_admin_scripts() 
{
	if (isset($_GET['page']) && $_GET['page'] == 'tat_theme_settings_menu')
	{
		 wp_enqueue_script('jquery');
		 wp_enqueue_script('media-upload');
		 wp_enqueue_script('thickbox');
		 wp_register_script('my-upload', TAT_WPMUT_PLUGIN_URL.'onetarek-wpmut-admin-script.js', array('jquery','media-upload','thickbox'));
		 wp_enqueue_script('my-upload');
	}
}

function tat_wpmut_admin_styles()
{
	if (isset($_GET['page']) && $_GET['page'] == 'tat_theme_settings_menu')
	{
		 wp_enqueue_style('thickbox');
	}
}
add_action('admin_print_scripts', 'tat_wpmut_admin_scripts');
add_action('admin_print_styles', 'tat_wpmut_admin_styles');

function  tat_theme_setting_page () {
 		echo '<div class="wrap">';
		echo '<div id="icon-options-general" class="icon32"></div><h2>Tat Theme Plugin</h2>';
		?>	
		<form method="post" action="options.php">
			<?php settings_fields( 'tat-theme-settings' ); ?>
			<?php $tat_theme_options_arr = get_option( 'tat_theme_options_arr' );	?>
			<table class="widefat">
				<thead>
					<tr><th colspan="2">Configuration</th></tr>
				</thead>
				<tr valign="top">
					<td><?php _e( 'Number of Hot News:', 'tat-themes-setting-plugin' ) ?></td>
					<td><input type="text" name="tat_theme_options_arr[num_of_show_tat_hot_news]" value="<?php echo esc_attr( $tat_theme_options_arr['num_of_show_tat_hot_news'] ); ?>" /></td>
				</th>
				<tr>
					<td width="150"><span class="field_name">Image Location 1</span></td>
					<td>
					<input type="text"  name="tat_theme_options_arr[image_location_1]" value="<?php echo esc_attr( $tat_theme_options_arr['image_location_1'] ); ?>" size="40" />
					<input type="button" class="onetarek-upload-button button" value="Upload Image" />
					<br /><span>Enter the image location or upload an image from your computer.</span>
					</td>
				</tr>
				<tr>
					<td width="150"><span class="field_name">Image Location 2</span></td>
					<td>
					<input type="text"  name="tat_theme_options_arr[image_location_2]" value="<?php echo esc_attr( $tat_theme_options_arr['image_location_2'] ); ?>" size="40" />
					<input type="button" class="onetarek-upload-button button" value="Upload Image" />
					<br /><span>Enter the image location or upload an image from your computer.</span>
					</td>
				</tr>
				<tr>
					<td width="150"><span class="field_name">Image Location 3</span></td>
					<td>
					<input type="text"  name="tat_theme_options_arr[image_location_3]" value="<?php echo esc_attr( $tat_theme_options_arr['image_location_3'] ); ?>" size="40" />
					<input type="button" class="onetarek-upload-button button" value="Upload Image" />
					<br /><span>Enter the image location or upload an image from your computer.</span>
					</td>
				</tr>
			</table>
			<p class="submit">
				<input type="submit" class="button-primary" value="Save Changes" />
			</p>
		</form>
<?php
	echo "</div>";
}
?>